package cn.fscode.code.generator.service.impl;

import cn.fscode.code.generator.assembly.GenTableAssembly;
import cn.fscode.code.generator.model.po.GenTableIndexPO;
import cn.fscode.code.generator.model.resp.GenTableIndexResp;
import cn.fscode.code.generator.repository.GenTableIndexRepository;
import cn.fscode.code.generator.service.GenTableIndexService;
import cn.fscode.commons.tool.core.exception.BizException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shenguangyang
 */
@Service
public class GenTableIndexServiceImpl implements GenTableIndexService {
    @Resource
    private GenTableIndexRepository genTableIndexRepository;
    @Resource
    private GenTableAssembly genTableAssembly;
    @Override
    public List<GenTableIndexResp> listGenTableIndexByTableId(Long tableId) {
        List<GenTableIndexPO> list = genTableIndexRepository.listByTableId(tableId);
        return list.stream().map(genTableAssembly::toGenTableIndexResp)
                .collect(Collectors.toList());
    }

    @Override
    public void deleteGenTableIndexByIds(List<Long> ids) {
        if (!genTableIndexRepository.removeByIds(ids)) {
            throw new BizException("删除失败");
        }
    }
}
